package com.gxwz.document.business.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.gxwz.document.core.pagination.Result;
import com.gxwz.document.business.entity.Literature;
import com.gxwz.document.business.entity.Recyclebin;
import com.gxwz.document.business.service.IrecyclebinService;
import com.gxwz.document.core.action.BaseAction;

@SuppressWarnings("serial")
public class RecyclebinAction extends BaseAction {
	protected static final String LIST_JSP = "/WEB-INF/page/deleted/deleted_list.jsp";
	private Recyclebin rb;
	private Literature lit;
	private List<Recyclebin> ListRecyclebin;
	HttpSession session = ServletActionContext.getRequest().getSession();
	private int totalRow  = 0;
	
	@Autowired
	private IrecyclebinService rbService;

	public String list()throws Exception{

		System.out.println("page:"+page);
		row = (page-1)*DEFUALT_PAGE_SIZE; 
		
		totalRow = rbService.getRowNum();
		if(page>(rbService.getRowNum()/DEFUALT_PAGE_SIZE+1)){
			page--;
		}
		if(row > rbService.getRowNum() || maxpage == 1){
			ListRecyclebin = rbService.findByPage((rbService.getRowNum()-(rbService.getRowNum()%DEFUALT_PAGE_SIZE)),DEFUALT_PAGE_SIZE);
		}else {
			ListRecyclebin = rbService.findByPage(row,DEFUALT_PAGE_SIZE);
		}
		setForwardView(LIST_JSP);
		return SUCCESS;
	}

	public String delete() throws Exception{
		rbService.delete(rb.getRbId());
		return list();
	}
	
	public String openlist(){
		forwardView = LIST_JSP;
		ListRecyclebin = rbService.findByPage(0, 5);
		return SUCCESS;
	}
	
	public Recyclebin getRecyclebin() {
		return rb;
	}

	public void setRecyclebin(Recyclebin rb) {
		this.rb = rb;
	}

	public List<Recyclebin> getListRecyclebin() {
		return ListRecyclebin;
	}

	public List<Recyclebin> setListRb(List<Recyclebin> listRecyclebin) {
		return ListRecyclebin = listRecyclebin;
	}

	public int getTotalRow() {
		return totalRow;
	}

	public void setTotalRow(int totalRow) {
		this.totalRow = totalRow;
	}
	

}
